package com.woniu.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.entity.HouseHoldinfos;
import com.woniu.service.IHouseHoldinfosService;
import com.woniu.util.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Gapper
 * @since 2021-03-29
 */
@RestController
public class HouseHoldinfosController {

    @Autowired
    private IHouseHoldinfosService houseHoldinfosService;

    /**
     * 增加
     */
    @PostMapping("/householdinfos/save")
    private ResultVO save(@RequestBody HouseHoldinfos houseHoldinfos){
        int i=0;
        try {
            i = houseHoldinfosService.CustomSave(houseHoldinfos);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return (i>0 ? ResultVO.success() : ResultVO.failure());

    }

    /**
     * 删除一个或者多个
     */
    @PostMapping("/householdinfos/deletes")
  private ResultVO deletes(@RequestBody String hid) {
        boolean flag;
        try {
            flag = houseHoldinfosService.removeByIds(Arrays.asList(hid));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return (flag ? ResultVO.success() : ResultVO.failure());
    }

    /**
     * 修改
     */
    @PostMapping("/householdinfos/updateById")
    private ResultVO updateById(@RequestBody HouseHoldinfos houseHoldinfos) {
        boolean flag;
        try {
            flag = houseHoldinfosService.updateById(houseHoldinfos);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return (flag ? ResultVO.success() : ResultVO.failure());
    }

    /**
     * 查询全部
     */
    @PostMapping("/householdinfos/findAll")
    private ResultVO findAll(@RequestBody HouseHoldinfos houseHoldinfos){
        IPage<HouseHoldinfos> list=null;
        try {
            list = houseHoldinfosService.findAll(houseHoldinfos);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        System.out.println(list.getRecords());

        return ResultVO.success(list);
    }

    /**
     * 查询一个
     */
    @PostMapping("/householdinfos/findById")
    private ResultVO findById(@RequestBody String hid) {
        HouseHoldinfos h = null;
        try {
            h = houseHoldinfosService.findById(hid);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        System.out.println(h);
        return ResultVO.success(h);
    }

    /**
     模糊查询
     */
    @PostMapping("/householdinfos/likeFind")
    private ResultVO likeFind(@RequestBody HouseHoldinfos houseHoldinfos){
        List<HouseHoldinfos> list=null;
        try {
            list= houseHoldinfosService.likeFind(houseHoldinfos);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return ResultVO.success(list);

    }

    /**
     梁磊查询一个
     */
    @PostMapping("/householdinfos/findByIds")
    private ResultVO findByIds(@RequestBody String hid){
        List<HouseHoldinfos> list=null;
        try {
             list = houseHoldinfosService.findByIds(hid);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failure();
        }
        return ResultVO.success(list);
    }

}

